class Solution
{
public:
    int countCompleteSubarrays(vector<int> &nums)
    {
        unordered_set<int> numSet(nums.begin(), nums.end());

        unordered_map<int, int> numCount;
        int result = 0;
        int start = 0;
        int end = 0;
        numCount[nums[0]] = 1;
        while (end < nums.size())
        {
            if (numCount.size() == numSet.size())
            {
                result += nums.size() - end;

                numCount[nums[start]]--;
                if (numCount[nums[start]] == 0)
                {
                    numCount.erase(nums[start]);
                }
                start++;
            }
            else
            {
                end++;
                if (end < nums.size())
                {
                    numCount[nums[end]]++;
                }
            }
        }
        return result;
    }
};